package com.erp.servlet;

import com.erp.bean.*;
import com.erp.service.*;
import com.erp.service.impl.EvaluateServiceImpl;
import com.erp.service.impl.OrderServiceImpl;
import com.erp.service.impl.SupplierServiceImpl;
import com.erp.util.factroy.ObjectFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author mtf
 * 已完成未评价列表控制器
 */
@WebServlet("/evaluateadd.action")
public class EvaluateAddServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        OrderService orderService = ObjectFactory.getServiceInstance("com.erp.service.impl.OrderServiceImpl", OrderService.class);
        EmpService empService = ObjectFactory.getServiceInstance("com.erp.service.impl.EmpServiceImpl",EmpService.class);
        CommodityService commodityService = ObjectFactory.getServiceInstance("com.erp.service.impl.CommodityServiceImpl", CommodityService.class);
        OrderStateService stateService = ObjectFactory.getServiceInstance("com.erp.service.impl.OrderStateServiceImpl", OrderStateService.class);
        List<Order>  list = orderService.findAll();
        List<Emp>  emps = empService.finAll();
        List<Commodity>  commodities = commodityService.findAll();
        List<OrderState>  states = stateService.findAll();
        //将订单列表保存到request

        req.setAttribute("emps",emps);
        req.setAttribute("commodities",commodities);
        req.setAttribute("states",states);

        List<Order>  orders = new ArrayList<>();
        //遍历出订单状态为已入库的订单
        for (Order order:list) {
            if (order.getSid()==8){
                orders.add(order);
            }
        }
        req.setAttribute("orders",orders);
        //创建商品业务逻辑对象
        //创建供应商业务逻辑对象
        SupplierService supplierService = new SupplierServiceImpl();
        List<Supplier> suppliers = supplierService.findAll();
        req.setAttribute("suppliers",suppliers);
        req.getRequestDispatcher("evaluateadd.jsp").forward(req,resp);

        //创建评价业务逻辑对象
        //先获取贫家内容
        //。。。。
        //Evaluate new一个对象
        //add


        //req.getRequestDispatcher("evaluateadd.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
